package core;

import java.util.Random;

public abstract class Door extends Inanimate {
	Random randomGen = new Random();

	public Door() {
		super();
		this.setVisible(true);
	}

	/* Place the door in a specific place */
	public Door(int pos) {
		super();
		this.setPos(pos);
		this.setVisible(true);
	}

	/* Place the door in place of a wall */
	public Door(int longSide, int shortSide) {
		this();
		int index;
		while (true) {
			index = randomGen.nextInt((longSide * shortSide) - 1);
			if ((index / longSide == 0)
					|| (index / longSide == (shortSide - 1))
					|| (index % longSide == 0)
					|| (index % longSide == (longSide - 1)))
				break;
		}
		this.setPos(index);
	}

	public Door(int entrancePos, int longSide, int shortSide) {
		this();
		int index;
		while (true) {
			index = randomGen.nextInt((longSide * shortSide) - 1);
			if (((index / longSide == 0)
					|| (index / longSide == (shortSide - 1))
					|| (index % longSide == 0) || (index % longSide == (longSide - 1)))
					&& (index != entrancePos))
				break;
		}
		this.setPos(index);
	}

	@Override
	public String toString() {
		return "Door [" + "]" + super.toString();
	}

}
